<table class="table">
	<div class="search">
		<a href="" class="btn-green ajax-load" data-page="<?= CHtml::normalizeUrl(array('page/slider'))?>"> + Добавить слайдер</a>
	</div>
	<thead>
	<td>ID</td>
	<td>Заголовок</td>
	<td>Видимость</td>
	<td>Операции</td>
	</thead>
	<tbody>
	<? foreach ($items as $item): ?>
		<tr>
			<td><?= $item->id ?></td>
			<td><?= $item->title ?></td>
			<td class="skip" style="text-align: center;">
				<select class="ajax-switch isVisible" data-id="<?= $item->id ?>">
					<option value="1"<?= ($item->isVisible)?" selected":"" ?>></option>
					<option value="0"<?= (!$item->isVisible)?" selected":"" ?>></option>
				</select>
			</td>
			<td>
				<div class="btn-group">
					<a class="btn btn-green icon ajax-load" href="#edit" data-page="<?= CHtml::normalizeUrl(array('page/slider', 'id'=>$item->id))?>">i</a>
					<a class="btn btn-green icon confirm-delete" href="<?= CHtml::normalizeUrl(array('page/deletedSlider', 'id'=>$item->id))?> ">g</a>
				</div>
			</td>
		</tr>
	<? endforeach ?>
	</tbody>
</table>
<script type="application/javascript">
$(function(){
	var ajaxSwitchIDisVisi = 0;
	$('.ajax-switch.isVisible').each(function() {
		$(this).attr('data-sid', ajaxSwitchIDisVisi);
		temp = "";
		leftSpace = "";
		if ($(this).val() == 1) {
			temp = " true";
			leftSpace = "style='left: 1em;'"
		}
		$(this).after("<div class='ajax-switcher"+temp+" isVisible' data-sid='"+ajaxSwitchIDisVisi+"' data-state='1'><div class='toggle' "+leftSpace+"></div></div>");
		$(this).hide();

		ajaxSwitchIDisVisi++;
	});

	$('.ajax-switcher.isVisible').click(function() {
		$(this).toggleClass('true');

		var thisSwitch = $('.ajax-switch[data-sid="'+$(this).data('sid')+'"]');
		if($(this).hasClass('true')) {
			$('.toggle', $(this)).animate({'left' : '1em'}, 200);
			thisSwitch.val(1);
		} else {
			$('.toggle', $(this)).animate({'left': '0em'}, 200);
			thisSwitch.val(0);
		}
		$.get('<?=CHtml::normalizeUrl(array('page/SliderVisible'))?>',{id:thisSwitch.data('id'), status:thisSwitch.val()}).done(humane.log('Изменено'));
	});
})
</script>